package com.wanmait.deliverymangementsystem.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.deliverymangementsystem.mapper.TasksMapper;
import com.wanmait.deliverymangementsystem.pojo.Tasks;
import com.wanmait.deliverymangementsystem.service.TaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TasksServiceImpl implements TaskService {
    @Resource
    private TasksMapper tasksMapper;
    @Override
    public void createTask(Tasks tasks) {
        tasksMapper.insert(tasks);
    }

    @Override
    public Integer findLastID() {
        return tasksMapper.findLastID();
    }

    @Override
    public Tasks findByID(Integer id) {
        return tasksMapper.findByID(id);
    }

    @Override
    public void accept(Tasks tasks) {
        tasksMapper.updateEstimatedTimeAndRunnerIDandStatus(tasks);
    }

    @Override
    public PageInfo<Tasks> runnerFindMyOrders(Integer page, Integer id) {
        PageHelper.startPage(page,5);
        List<Tasks> tasksList =tasksMapper.SelectByRunnerIDAndStatus(id);
        PageInfo<Tasks> tasksPageInfo =new PageInfo<>(tasksList,3);
            return tasksPageInfo;
    }

    @Override
    public void cancelTask(Integer id) {
        tasksMapper.updateStatusById(id);
    }

    @Override
    public void complete(Integer id) {
        tasksMapper.updateStautusto3ByID(id);
        tasksMapper.updateCompletedAtByID(id);
    }
}
